import * as Type from "./types";
import { IAction } from "../../../../common/store/actions";

export const defaultState = {
  list: [],
  tableLoading: false
};

export default (state: typeof defaultState = defaultState, action: IAction) => {
  switch (action.type) {
    case Type.GET_LIST: {
      const newState: typeof defaultState = JSON.parse(JSON.stringify(state));
      newState.list = action.data;
      return newState;
    }
    case Type.SET_TABLE_LOADING: {
      const newState: typeof defaultState = JSON.parse(JSON.stringify(state));
      newState.tableLoading = action.data;
      return newState;
    }
    default: {
      return state;
    }
  }
};
